/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaModificarRelaciones.java
 *
 * Created on 14-may-2012, 12:05:46
 */
package gui;

import ClasesAModificar.DocumentoModificar;
import controles.ControlModificacion;
import javax.swing.JOptionPane;
import src.BorraCeldas;
import src.Core;

/**
 *
 * @author usuario_local
 */
public class VentanaModificarRelaciones extends javax.swing.JFrame {

    int padre;
    VentanaModificarDocumento vmd;
    VentanaModificarAcontecimiento vma;
    VentanaModificarColectivo vmc;
    VentanaModificarPersonaje vmp;
    
    /** Creates new form VentanaModificarRelaciones */
    public VentanaModificarRelaciones(int i, VentanaModificarDocumento vmd, String str, int idPadre) {
        padre = i;
        this.vmd = vmd;
        this.idPadre=idPadre;
        initComponents();
        actualizaCampoTexto(str);
    }
    
    public VentanaModificarRelaciones(int i, VentanaModificarAcontecimiento vma, String str, int idPadre) {
        padre = i;
        this.vma = vma;
        this.idPadre=idPadre;
        initComponents();
        actualizaCampoTexto(str);
    }

    public VentanaModificarRelaciones(int i, VentanaModificarColectivo vmc, String str, int idPadre) {
        padre = i;
        this.vmc = vmc;
        this.idPadre=idPadre;
        initComponents();
        actualizaCampoTexto(str);
    }
    
    public VentanaModificarRelaciones(int i, VentanaModificarPersonaje vmp, String str, int idPadre) {
        padre = i;
        this.vmp = vmp;
        this.idPadre=idPadre;
        initComponents();
        actualizaCampoTexto(str);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_vanSeleccion = new javax.swing.JTextArea();
        jLabel_vanSeleccion = new javax.swing.JLabel();
        jTextField_vanSeleccion = new javax.swing.JTextField();
        jButton_VMREliminar = new javax.swing.JButton();
        jButtonVMRañadir = new javax.swing.JButton();
        jButton_VMRSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jTextArea_vanSeleccion.setColumns(20);
        jTextArea_vanSeleccion.setEditable(false);
        jTextArea_vanSeleccion.setRows(5);
        jScrollPane2.setViewportView(jTextArea_vanSeleccion);

        jLabel_vanSeleccion.setText("Indice a eliminar");

        jButton_VMREliminar.setText("Eliminar");
        jButton_VMREliminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_VMREliminarMouseClicked(evt);
            }
        });

        jButtonVMRañadir.setText("Añadir");
        jButtonVMRañadir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonVMRañadirMouseClicked(evt);
            }
        });

        jButton_VMRSalir.setText("Salir");
        jButton_VMRSalir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_VMRSalirMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel_vanSeleccion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField_vanSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
                        .addComponent(jButton_VMREliminar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonVMRañadir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_VMRSalir))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vanSeleccion)
                    .addComponent(jTextField_vanSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton_VMRSalir)
                    .addComponent(jButtonVMRañadir)
                    .addComponent(jButton_VMREliminar)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void actualizaCampoTexto(String str)
{
    jTextArea_vanSeleccion.setText(str);
}
    
private void jButton_VMRSalirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_VMRSalirMouseClicked
// TODO add your handling code here:
    switch(padre){
        case 1:
            vmd.setVisible(true);
            this.setVisible(false);
            this.dispose();
            break;
        case 2:
            vmd.setVisible(true);
            this.setVisible(false);
            this.dispose();
            break;
        case 3:
            vmd.setVisible(true);
            this.setVisible(false);
            this.dispose();
            break;
        case 4:
            vma.setVisible(true);
            this.setVisible(false);
            this.dispose();
            break;
        case 5:
            vmc.setVisible(true);
            this.setVisible(false);
            this.dispose();
            break;
        case 6:
            vmp.setVisible(true);
            this.setVisible(false);
            this.dispose();
            break;
        case 7:
            vmp.setVisible(true);
            this.setVisible(false);
            this.dispose();
            break;
    }
}//GEN-LAST:event_jButton_VMRSalirMouseClicked

private void jButtonVMRañadirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonVMRañadirMouseClicked
// TODO add your handling code here:
    switch(padre){
        case 1:
            //Relacion documento Personaje
            VentanaAnadir va = new VentanaAnadir(8, this,idPadre);
            va.setTexto(Core.dameTodosPersonajes());
            va.setVisible(true);
            this.setVisible(false);
            break;
        case 2:
            //Relacion DocumentoAcontecimiento
            VentanaAnadir va2 = new VentanaAnadir(9, this,idPadre);
            va2.setTexto(Core.dameTodosAcontecimientos());
            va2.setVisible(true);
            this.setVisible(false);
            break;
        case 3:
            //Relacion DocumentoColectivo
            VentanaAnadir va3 = new VentanaAnadir(10, this,idPadre);
            va3.setTexto(Core.dameTodosColectivos());
            va3.setVisible(true);
            this.setVisible(false);
            break; 
        case 4:
            //Relacion acontecimientofichero
            VentanaAnadir va4 = new VentanaAnadir(11,this,idPadre);
            va4.setTexto(Core.dameTodosFicheros());
            va4.setVisible(true);
            this.setVisible(false);
            break;
        case 5:
            //Relacion colectivoFichero
            VentanaAnadir va5 = new VentanaAnadir(12,this,idPadre);
            va5.setVisible(true);
            va5.setTexto(Core.dameTodosFicheros());
            this.setVisible(false);
            break;
        case 6:
            //Relacion personajeAlias
            VentanaAnadir va6 = new VentanaAnadir(13,this,idPadre);
            va6.setVisible(true);
            this.setVisible(false);
            break;
        case 7:
            //Relacion personajeCargo
            VentanaTiempo vt = new VentanaTiempo(3, this,idPadre);
            vt.setVisible(true);
            this.setVisible(false);
            break;
    }
}//GEN-LAST:event_jButtonVMRañadirMouseClicked

    private void jButton_VMREliminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_VMREliminarMouseClicked
        
        try{
            Integer.parseInt(this.jTextField_vanSeleccion.getText());
        
            int eliminar = Integer.valueOf(jTextField_vanSeleccion.getText());
            switch(padre){
            case 1:
                vmd.setVisible(true);
                this.setVisible(false);
                BorraCeldas.desLinkaPersonajeConDocumento(eliminar, idPadre);
                this.dispose();
                break;
            case 2:
                vmd.setVisible(true);
                this.setVisible(false);
                BorraCeldas.desLinkaAcontecimientoConDocumento(eliminar, idPadre);
                this.dispose();
                break;
            case 3:
                vmd.setVisible(true);
                this.setVisible(false);
                BorraCeldas.desLinkaColectivoConDocumento(eliminar, idPadre);
                this.dispose();
                break;
            case 4:
                vma.setVisible(true);
                this.setVisible(false);
                BorraCeldas.desLinkaFicheroConAcontecimiento(eliminar, idPadre);
                this.dispose();
                break;
            case 5:
                vmc.setVisible(true);
                this.setVisible(false);
                BorraCeldas.desLinkaFicheroConColectivo(eliminar, idPadre);
                this.dispose();
                break;
            case 6:
                vmp.setVisible(true);
                this.setVisible(false);
                BorraCeldas.desLinkaAliasConPersonaje(String.valueOf(eliminar), idPadre);
                this.dispose();
                break;
            case 7:
                vmp.setVisible(true);
                this.setVisible(false);
                BorraCeldas.desLinkaCargoConPersonaje(eliminar, idPadre); 
                this.dispose();
                break;
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Por favor introduzca el numero que represente el indice que desea eliminar");
        }
    }//GEN-LAST:event_jButton_VMREliminarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonVMRañadir;
    private javax.swing.JButton jButton_VMREliminar;
    private javax.swing.JButton jButton_VMRSalir;
    private javax.swing.JLabel jLabel_vanSeleccion;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea_vanSeleccion;
    private javax.swing.JTextField jTextField_vanSeleccion;
    // End of variables declaration//GEN-END:variables
    private int idPadre;
}
